'use strict';

module.exports = {
    up: async (queryInterface, Sequelize) => {
        const { STRING, INTEGER, DATE, BOOLEAN, NOW } = Sequelize;

        await queryInterface.createTable(
            'tbl_user',
            {
                id: {
                    type: INTEGER,
                    primaryKey: true,
                    autoIncrement: true
                },
                username: {
                    type: STRING(32),
                    allowNull: false
                },
                password: {
                    type: STRING(32),
                    allowNull: false
                },
                type: {
                    type: INTEGER,
                    allowNull: false,
                    defaultValue: 1
                },
                state: {
                    type: INTEGER,
                    allowNull: false,
                    defaultValue: 1
                },
                grant_type: {
                    type: INTEGER,
                    allowNull: false,
                    defaultValue: 1
                },
                role_id: {
                    type: INTEGER,
                    allowNull: true
                },
                third_id: {
                    type: STRING(64),
                    allowNull: true
                },
                gender: {
                    type: INTEGER,
                    allowNull: true
                },
                birthday: {
                    type: DATE,
                    allowNull: true
                },
                nickname: {
                    type: STRING(32),
                    allowNull: true
                },
                phone: {
                    type: STRING(32),
                    allowNull: true
                },
                email: {
                    type: STRING(32),
                    allowNull: true
                },
                avatar: {
                    type: STRING(255),
                    allowNull: true
                },
                note: {
                    type: STRING(255),
                    allowNull: true
                },
                created_at: {
                    type: DATE,
                    allowNull: false,
                    defaultValue: NOW
                },
                updated_at: {
                    type: DATE,
                    allowNull: false,
                    defaultValue: NOW
                }
            },
            {
                charset: 'utf8'
            });

        await queryInterface.createTable(
            'tbl_admin',
            {
                id: {
                    type: INTEGER,
                    primaryKey: true,
                    autoIncrement: true
                },
                username: {
                    type: STRING(32),
                    allowNull: false
                },
                password: {
                    type: STRING(32),
                    allowNull: false
                },
                type: {
                    type: INTEGER,
                    allowNull: false,
                    defaultValue: 1
                },
                status: {
                    type: BOOLEAN,
                    allowNull: false,
                    defaultValue: true
                },
                grant_type: {
                    type: INTEGER,
                    allowNull: false,
                    defaultValue: 1
                },
                role_id: {
                    type: INTEGER,
                    allowNull: true
                },
                avatar: {
                    type: STRING(255),
                    allowNull: true
                },
                note: {
                    type: STRING(255),
                    allowNull: true
                },
                created_at: {
                    type: DATE,
                    allowNull: false,
                    defaultValue: NOW
                },
                updated_at: {
                    type: DATE,
                    allowNull: false,
                    defaultValue: NOW
                }
            },
            {
                charset: 'utf8'
            });
    },

    down: async (queryInterface, Sequelize) => {
        // await queryInterface.dropTable('tbl_user');
        // await queryInterface.dropTable('tbl_admin');
    }
};
